package routers

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

const (
	SUCCESS = "success"
	FAIL    = "fali"
)

type Result struct {
	StatusCode int         `json:"-"`
	Code       int         `json:"code"`
	Msg        interface{} `json:"msg"`
}

func Response(data interface{}) *Result {
	return &Result{
		StatusCode: http.StatusOK,
		Code:       http.StatusOK,
		Msg:        data,
	}
}

func ResHandler(c *gin.Context, data interface{}) {
	res := Response(data)
	c.JSON(res.StatusCode, res)
}

func ResHandlerWithStatus(c *gin.Context, status string, data interface{}) {
	ResHandler(c, gin.H{
		"status": status,
		"data":   data,
	})
}

func ResHandlerWithOk(c *gin.Context, data interface{}) {
	ResHandlerWithStatus(c, SUCCESS, data)
}
func ResHandlerOk(c *gin.Context, msg string) {
	ResHandlerWithOk(c, msg)
}

func ResHandlerWithFault(c *gin.Context, data interface{}) {
	ResHandlerWithStatus(c, FAIL, data)
}
func ResHandlerFault(c *gin.Context, msg string) {
	ResHandlerWithFault(c, msg)
}
